<style>
    .xxpayPopupDiv .layui-form-label {
        width: 160px;
    }
    .xxpayPopupDiv #paramInfo .layui-input , .layui-textarea{
        width: 80%;
    }
    #cDInfo td {
        border: none;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <fieldset class="layui-elem-field">
                    <legend><button class='layui-btn layui-btn-xs layui-btn-danger'>基本信息</button></legend>
                    <form class="layui-form" >
                        <div class="layui-form-item">
                            <label class="layui-form-label">账户名称</label>
                            <div class="layui-input-inline" style="width:30%">
                                <input type="text" name="accountName" id="accountName" placeholder="请输入账户名称" class="layui-input" >
                            </div>
                            <label class="layui-form-label">轮询权重</label>
                            <div class="layui-input-inline" style="width:30%">
                                <input type="text" name="pollWeight" id="pollWeight" lay-verify="required|number" placeholder="请输入轮询权重,1-9之间数字" class="layui-input" >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">账户状态</label>
                            <div class="layui-input-inline" style="width:30%">
                                <input type="radio" name="status" value="1" title="开启" checked="checked">
                                <input type="radio" name="status" value="0" title="关闭" >
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">渠道商户ID</label>
                            <div class="layui-input-inline" style="width:30%">
                                <input type="text" id="passageMchId" placeholder="请输入支付渠道商户ID" class="layui-input" >
                            </div>
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-inline" style="width:30%">
                                <input type="text" name="remark" id="remark" placeholder="请输入备注信息" class="layui-input" >
                            </div>
                        </div>
                        <button type="button" lay-submit  lay-filter="btnParam" class="layui-hide xxpayYesBtn">保存</button>
                    </form>
                </fieldset>

                <fieldset class="layui-elem-field">
                    <legend><button class='layui-btn layui-btn-xs layui-btn-danger'>选择转卡通道银行卡</button></legend>
                    <table class="layui-table">
                        <thead>
                        <tr><th>选择</th><th>卡号</th><th>账户名</th><th>银行名称</th><th>账户余额</th><th>MID</th><th>状态</th></tr>
                        </thead>
                        <tbody id="tccardTBody"></tbody>
                    </table>
                    <button id="loadMoreDataBtn" class="layui-btn layui-btn-normal" style="width: 100%; background-color: #79a5e6">加载更多</button>
                </fieldset>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','table','util','admin',],function(){
        var form = layui.form
                , $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , element = layui.element
                , view = layui.view
                , table = layui.table;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        var currentPageIndex = 0;
        var listPageSize = 10;

        var id = view.getOpenParams('id');
        var payPassageId;
        var mustFromTemplate = true; //是否强制使用模板

        admin.req({
            type: 'post',
            url: layui.setter.baseUrl + '/config/pay_passage_account/get',
            data: {
                id: id
            },
            error: function(err){
                layer.alert(err);
            },
            success: function(res){
                if(res.code == 0){
                    // 设置基础信息
                    payPassageId = res.data.payPassageId;
                    var templateId = res.data.templateId; //账号模板ID
                    var ifTypeCode = res.data.ifTypeCode;

                    $('#accountName').val(res.data.accountName);
                    $('#pollWeight').val(res.data.pollWeight);
                    $("input[name='status'][value='"+res.data.status+"']").attr("checked",true);
                    $('#passageMchId').val(res.data.passageMchId);
                    $('#remark').val(res.data.remark);

                    form.render();
                }else{
                    layer.alert(res.msg,{title:"请求失败"})
                }
            }
        })

        form.render();

        form.on('submit(btnParam)', function(data){

            var passageMchId = $.trim($('#passageMchId').val());
            var templateId = $('#accountTemplateSelect').val();
            var accountName = $.trim($('#accountName').val());
            var pollWeight = $.trim($('#pollWeight').val());
            if(accountName == '') {
                layer.alert("请输入账户名称",{title: '提示'});
                return false;
            }
            if(passageMchId == '') {
                layer.alert("请输入渠道商户ID",{title: '提示'});
                return false;
            }

            var accountNoList = [];

            for(let i = 0; i < $(".tccardRelaCheckbox:checked").length; i++){

                let thisCheckbox = $(".tccardRelaCheckbox:checked").eq(i);
                accountNoList.push($(thisCheckbox).attr('accountNo'));
            }


            // if(accountNoList.length <= 0){
            //     layer.alert("请选择银行卡！",{title: '提示'});
            //     return false;
            // }


            var remark = $.trim($('#remark').val());
            var status = $.trim($('input[name="status"]:checked').val());
            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/config/pay_passage_account/update',
                data: {
                    id : id,
                    accountName: accountName,
                    pollWeight: pollWeight,
                    templateId: templateId,
                    status: status,
                    remark: remark,
                    passageMchId: passageMchId,
                    param: "{}",
                    accountNoListStr: JSON.stringify(accountNoList)
                },
                error: function(err){layer.alert(err.msg,{title:"请求失败"})},
                success: function(res){
                    if(res.code == 0){
                        layer.alert(res.msg, {title: '保存成功'},function(index){
                            layer.closeAll(); //关闭所有弹层
                            layui.table.reload('tableReload'); //调用业务弹层外表格重新加载
                        });
                    }
                }
            })
            return false;
        });
    })
</script>